﻿package mortal.game.view.battlefield
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.cache.battlefield.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.rules.*;
    import mortal.game.view.common.*;
    import mortal.game.view.copy.*;
    import mortal.game.view.mainUI.smallMap.view.*;
    import mortal.game.view.vip.panel.*;
    import mortal.mvc.core.*;

    public class BattlefieldMiniView extends CopyInfoPanelBase
    {
        protected var _isUpdateLeftTime:Boolean = false;
        private var _smallMap:SmallMapEmbedView;
        private var _tfKill:GTextFiled;
        private var _tfDead:GTextFiled;
        private var _tfAssists:GTextFiled;
        private var _tfHonor:GTextFiled;
        private var _linkButtonBang:GButton;
        private var _linkButtonHonorShop:GButton;
        private var _battleCampScore1:BattleCampScore;
        private var _battleCampScore2:BattleCampScore;
        private var _battleCampScore3:BattleCampScore;
        private var _leftTimeBg:ScaleBitmap;
        private var _leftTime:SecTimerView;
        private var _taskDes:GTextFiled;
        private var _taskKill:GTextFiled;
        private var _taskDead:GTextFiled;
        private var _taskAssists:GTextFiled;
        private var _taskReward:GTextFiled;
        private var _btnGetTaskReward:GButton;
        private var _btnExit:GLoadingButton;
        private static var _instance:BattlefieldMiniView;

        public function BattlefieldMiniView()
        {
            super(ImagesConst.copyInfoPanelTitleBattlefield, 262, 584);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            setSize(262, 584);
            pushUIToDisposeVec(UIFactory.gImageBitmap(ImagesConst.BattlefieldMiniViewBg, 0, 0, _bodySprite));
            this._smallMap = UIFactory.smallMapEmbedView(ImagesConst.BattleFieldMiniMap, 17, 44, _bodySprite, true);
            this._smallMap.run();
            this._leftTimeBg = UIFactory.bg(12, 43, 243, 22, _bodySprite, "RegionTitleBg");
            this._leftTime = UIFactory.getUICompoment(SecTimerView);
            this._leftTime.defaultTextFormat = GlobalStyle.textFormatLv;
            this._leftTime.filters = [FilterConst.glowFilter];
            this._leftTime.setParse(Language.getString(11306));
            this._leftTime.mouseEnabled = false;
            UIFactory.setObjAttri(this._leftTime, 60, 43, 150, 20, _bodySprite);
            pushUIToDisposeVec(UIFactory.bg(12, 252, 243, 22, _bodySprite, "RegionTitleBg"));
            this._linkButtonBang = UIFactory.gButton(Language.getString(11307), 18, 252, 78, 22, _bodySprite, "BlueLinkButton");
            this._linkButtonHonorShop = UIFactory.gButton(Language.getString(11304), 171, 252, 78, 22, _bodySprite, "GreenLinkButton");
            var _loc_1:int = 263;
            this._tfKill = UIFactory.gTextField(Language.getString(11308) + Language.getStringByParam(11313, "0"), 24, 27 + _loc_1, 75, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._tfDead = UIFactory.gTextField(Language.getString(11309) + Language.getStringByParam(11314, "0"), 94, 27 + _loc_1, 75, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._tfAssists = UIFactory.gTextField(Language.getString(11310) + Language.getStringByParam(11314, "0"), 164, 27 + _loc_1, 75, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._tfHonor = UIFactory.gTextField(Language.getString(11311) + "0", 24, 52 + _loc_1, 75, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._battleCampScore1 = UIFactory.getUICompoment(BattleCampScore, 24, 75 + _loc_1, _bodySprite);
            this._battleCampScore2 = UIFactory.getUICompoment(BattleCampScore, 24, 98 + _loc_1, _bodySprite);
            this._battleCampScore3 = UIFactory.getUICompoment(BattleCampScore, 24, 123 + _loc_1, _bodySprite);
            this._taskDes = UIFactory.gTextField(Language.getString(11315), 26, 156 + _loc_1, 170, 20, _bodySprite, GlobalStyle.textFormatPutong);
            this._taskKill = UIFactory.gTextField(Language.getString(11308) + Language.getStringByParam(11316, "0", "3"), 26, 176 + _loc_1, 100, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._taskDead = UIFactory.gTextField(Language.getString(11309) + Language.getStringByParam(11316, "0", "5"), 96, 176 + _loc_1, 100, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._taskAssists = UIFactory.gTextField(Language.getString(11310) + Language.getStringByParam(11316, "0", "30"), 166, 176 + _loc_1, 100, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._taskReward = UIFactory.gTextField(Language.getString(11317), 26, 200 + _loc_1, 120, 20, _bodySprite, GlobalStyle.textFormatPutong, true);
            this._btnGetTaskReward = UIFactory.gButton(Language.getString(11318), 146, 197 + _loc_1, 45, 22, _bodySprite);
            var _loc_2:* = UICompomentPool.getUICompoment(VipOpenTipsPanel);
            _loc_2.move(12, 220 + _loc_1);
            var _loc_3:int = 32;
            _loc_2.resetLevelTextPos(36, 9, 36, 9);
            _loc_2.resetValueTextPos(114, 9, 114, 9);
            _loc_2.bgUrl = ImagesConst.vipOpenTipsBg_mid;
            _loc_2.valueType = VipOpenTipsPanel.numberValue;
            _loc_2.vipType = EVipRecordType._EVipRecordTypeBattlehonour;
            _bodySprite.addChild(_loc_2);
            pushUIToDisposeVec(_loc_2);
            this._btnExit = UIFactory.gLoadingButton(ResFileConst.ExitCopyBtn, 80, 260 + _loc_1, 103, 38, _bodySprite);
            var _loc_4:* = new Date();
            this._battleCampScore1.updateForceScore(new BattlefieldScore(8, 0, 0));
            this._battleCampScore2.updateForceScore(new BattlefieldScore(9, 0, 0));
            this._battleCampScore3.updateForceScore(new BattlefieldScore(10, 0, 0));
            this._linkButtonBang.configEventListener(MouseEvent.CLICK, this.onClickBang);
            this._linkButtonHonorShop.configEventListener(MouseEvent.CLICK, this.onClickHonorShop);
            this._btnGetTaskReward.configEventListener(MouseEvent.CLICK, this.onClickGetTask);
            this._btnExit.configEventListener(MouseEvent.CLICK, this.onClickExit);
            this.updatePlayerScore(new SMyScore());
            return;
        }// end function

        private function onClickExit(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CopyClickQuickBtn));
            return;
        }// end function

        protected function onClickHonorShop(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.NPC_OpenNpcShop, ShopType.Honor));
            return;
        }// end function

        protected function onClickGetTask(event:MouseEvent) : void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldGetTaskReward));
            return;
        }// end function

        private function onClickBang(event:MouseEvent) : void
        {
            if (BattlefieldResultWindow.instance.isHide)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.BattlefieldRequstResult));
                BattlefieldResultWindow.instance.show();
            }
            return;
        }// end function

        public function updateAll() : void
        {
            if (Cache.instance.battlefieldCache.myScore)
            {
                this.updatePlayerScore(Cache.instance.battlefieldCache.myScore);
            }
            if (Cache.instance.battlefieldCache.battlefieldScoreList)
            {
                this.updateForceScore(Cache.instance.battlefieldCache.battlefieldScoreList);
            }
            return;
        }// end function

        public function updatePlayerScore(param1:SMyScore) : void
        {
            var _loc_2:int = 0;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            this.updateLeftTime();
            var _loc_5:Boolean = false;
            if (param1.killPlayer >= 3)
            {
                _loc_2 = 3;
                _loc_5 = true;
            }
            else
            {
                _loc_2 = param1.killPlayer;
            }
            if (param1.killed >= 5)
            {
                _loc_3 = 5;
                _loc_5 = true;
            }
            else
            {
                _loc_3 = param1.killed;
            }
            if (param1.assist >= 30)
            {
                _loc_4 = 30;
                _loc_5 = true;
            }
            else
            {
                _loc_4 = param1.assist;
            }
            ObjTeamCreate.setTextFieldKeyValue(this._tfKill, Language.getString(11308), Language.getStringByParam(11313, param1.killPlayer.toString()), GlobalStyle.colorPutong, GlobalStyle.colorHuang);
            ObjTeamCreate.setTextFieldKeyValue(this._tfDead, Language.getString(11309), Language.getStringByParam(11314, param1.killed.toString()), GlobalStyle.colorPutong, GlobalStyle.colorHuang);
            ObjTeamCreate.setTextFieldKeyValue(this._tfAssists, Language.getString(11310), Language.getStringByParam(11314, param1.assist.toString()), GlobalStyle.colorPutong, GlobalStyle.colorHuang);
            ObjTeamCreate.setTextFieldKeyValue(this._tfHonor, Language.getString(11311), param1.honor.toString(), GlobalStyle.colorPutong, GlobalStyle.colorHuang);
            ObjTeamCreate.setTextFieldKeyValue(this._taskKill, Language.getString(11308), Language.getStringByParam(11316, _loc_2.toString(), "3"), GlobalStyle.colorPutong, GlobalStyle.colorLv);
            ObjTeamCreate.setTextFieldKeyValue(this._taskDead, Language.getString(11309), Language.getStringByParam(11316, _loc_3.toString(), "5"), GlobalStyle.colorPutong, GlobalStyle.colorLv);
            ObjTeamCreate.setTextFieldKeyValue(this._taskAssists, Language.getString(11310), Language.getStringByParam(11316, _loc_4.toString(), "30"), GlobalStyle.colorPutong, GlobalStyle.colorLv);
            if (param1.hasTask)
            {
                this._btnGetTaskReward.label = Language.getString(11318);
                this._btnGetTaskReward.enabled = _loc_5;
                if (_loc_5)
                {
                    EffectManager.glowFilterReg(this._btnGetTaskReward);
                }
                else
                {
                    EffectManager.glowFilterUnReg(this._btnGetTaskReward);
                }
            }
            else
            {
                this._btnGetTaskReward.enabled = false;
                this._btnGetTaskReward.label = Language.getString(11319);
                EffectManager.glowFilterUnReg(this._btnGetTaskReward);
            }
            return;
        }// end function

        public function updateForceScore(param1:Vector.<BattlefieldScore>) : void
        {
            this._battleCampScore1.updateForceScore(param1[0]);
            this._battleCampScore2.updateForceScore(param1[1]);
            this._battleCampScore3.updateForceScore(param1[2]);
            return;
        }// end function

        public function updateLeftTime() : void
        {
            if (Cache.instance.battlefieldCache.myScore && !this._isUpdateLeftTime)
            {
                this._isUpdateLeftTime = true;
                this._leftTime.setLeftTime(Cache.instance.battlefieldCache.myScore.secLeft, true);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._smallMap.dispose(param1);
            this._smallMap = null;
            this._tfKill.dispose(param1);
            this._tfDead.dispose(param1);
            this._tfAssists.dispose(param1);
            this._tfHonor.dispose(param1);
            this._linkButtonBang.dispose(param1);
            this._linkButtonHonorShop.dispose(param1);
            this._battleCampScore1.dispose(param1);
            this._battleCampScore2.dispose(param1);
            this._battleCampScore3.dispose(param1);
            this._leftTime.dispose(param1);
            this._taskDes.dispose(param1);
            this._taskKill.dispose(param1);
            this._taskDead.dispose(param1);
            this._taskAssists.dispose(param1);
            this._taskReward.dispose(param1);
            this._btnGetTaskReward.dispose(param1);
            this._btnExit.dispose(param1);
            this._tfKill = null;
            this._tfDead = null;
            this._tfAssists = null;
            this._tfHonor = null;
            this._linkButtonBang = null;
            this._linkButtonHonorShop = null;
            this._battleCampScore1 = null;
            this._battleCampScore2 = null;
            this._battleCampScore3 = null;
            this._leftTime = null;
            this._taskDes = null;
            this._taskKill = null;
            this._taskDead = null;
            this._taskAssists = null;
            this._taskReward = null;
            this._btnGetTaskReward = null;
            this._btnExit = null;
            this._leftTimeBg.dispose(param1);
            this._leftTimeBg = null;
            this._isUpdateLeftTime = false;
            super.disposeImpl(param1);
            return;
        }// end function

        public static function get instance() : BattlefieldMiniView
        {
            if (!_instance)
            {
                _instance = new BattlefieldMiniView;
            }
            return _instance;
        }// end function

        public static function hasInstance() : Boolean
        {
            return _instance != null;
        }// end function

    }
}
